package com.phkg.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.phkg.entity.*;
import com.phkg.mapper.PlaceMapper;
import com.phkg.mapper.UserMapper;
import org.neo4j.driver.internal.InternalPath;
import org.neo4j.driver.types.Relationship;
import org.neo4j.ogm.model.Property;
import org.neo4j.ogm.model.Result;
import org.neo4j.ogm.response.model.NodeModel;
import org.neo4j.ogm.session.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;

import static com.phkg.util.CosineSimilarAlgorithm.cosSimilarityByString;
import static oracle.jrockit.jfr.events.Bits.doubleValue;
import static oracle.jrockit.jfr.events.Bits.intValue;


@RestController
@RequestMapping("/neo4j")
public class Neo4jController {

    @Resource
    private Session session;

    @Autowired
    PlaceMapper placeMapper;

    /*查询全部节点*/
    @GetMapping("/node")
    public List<Neo4jBasicNode> getAllNode() {
        String cypherSql = "MATCH (p) RETURN p";
        Result query = session.query(cypherSql, new HashMap<>());
        ArrayList<Neo4jBasicNode> nodeList = new ArrayList<>();
        for (Map<String, Object> map : query.queryResults()) {
            NodeModel queryNode = (NodeModel) map.get("p");
            //System.out.println(queryNode);
            Neo4jBasicNode startNodeVo = new Neo4jBasicNode();
            startNodeVo.setIdentity(queryNode.getId());
            startNodeVo.setLabels(Arrays.asList(queryNode.getLabels()));
            List<Property<String, Object>> propertyList = queryNode.getPropertyList();
            HashMap<String, Object> proMap = new HashMap<>();
            for (Property<String, Object> stringObjectProperty : propertyList) {
                if (proMap.containsKey(stringObjectProperty.getKey())) {
                    throw new RuntimeException("数据重复");
                }
                proMap.put(stringObjectProperty.getKey(), stringObjectProperty.getValue());
            }
            startNodeVo.setProperties(proMap);
            nodeList.add(startNodeVo);
        }
        session.clear();
        return nodeList;
    }

    /*查询全部关系*/
    @GetMapping("/relation")
    public List<Neo4jQueryRelation> queryRelation() {
        String cypherSql = "match l=()-[]->() return l";
//        String cypherSql = "match ()-[l]-() return l"; /*这种写法springboot搜不到结果？*/
        Result query = session.query(cypherSql, new HashMap<>());
        ArrayList<Neo4jQueryRelation> returnList = new ArrayList<>();
        for (Map<String, Object> map : query.queryResults()) {
            InternalPath ps = (InternalPath) map.get("l");
            /*组装 relation*/
            Neo4jQueryRelation neo4JQueryRelation = new Neo4jQueryRelation();
            Relationship relationship = ps.relationships().iterator().next();
            neo4JQueryRelation.setStart(relationship.startNodeId());
            neo4JQueryRelation.setEnd(relationship.endNodeId());
            neo4JQueryRelation.setIdentity(relationship.id());
            neo4JQueryRelation.setType(relationship.type());
            neo4JQueryRelation.setProperties(relationship.asMap());

            returnList.add(neo4JQueryRelation);
        }
        session.clear();
        return returnList;
    }

    /*查询指定类型节点*/
    @GetMapping("/renderNode")
    public List<Neo4jBasicNode> getNodeByLabel(String[] label) {
        StringBuilder cypherSql = new StringBuilder("MATCH (p) WHERE ");
        for (int i = 0; i < label.length; i++) {
            if (i == 0) {
                cypherSql.append("labels(p)=['").append(label[i]).append("']");
            } else {
                cypherSql.append(" or labels(p)=['").append(label[i]).append("']");
            }
            if (label[i].equals("spirit")) {
                cypherSql.append(" or labels(p)=['period'] or labels(p)=['vipspirit']");
            }
        }
        cypherSql.append(" return p");
        Result query = session.query(cypherSql.toString(), new HashMap<>());
        ArrayList<Neo4jBasicNode> nodeList = new ArrayList<>();
        for (Map<String, Object> map : query.queryResults()) {
            NodeModel queryNode = (NodeModel) map.get("p");
            //System.out.println(queryNode);
            Neo4jBasicNode startNodeVo = new Neo4jBasicNode();
            startNodeVo.setIdentity(queryNode.getId());
            startNodeVo.setLabels(Arrays.asList(queryNode.getLabels()));
            List<Property<String, Object>> propertyList = queryNode.getPropertyList();
            HashMap<String, Object> proMap = new HashMap<>();
            for (Property<String, Object> stringObjectProperty : propertyList) {
                if (proMap.containsKey(stringObjectProperty.getKey())) {
                    throw new RuntimeException("数据重复");
                }
                proMap.put(stringObjectProperty.getKey(), stringObjectProperty.getValue());
            }
            startNodeVo.setProperties(proMap);
            nodeList.add(startNodeVo);
        }
        session.clear();
        return nodeList;
    }

    /*查询精神节点*/
    @GetMapping("/spirit")
    public List<Neo4jBasicNode> getSpiritNode() {
        String cypherSql = "MATCH (p) WHERE labels(p)=['spirit'] or labels(p)=['vipspirit'] RETURN p";
        Result query = session.query(cypherSql, new HashMap<>());
        ArrayList<Neo4jBasicNode> nodeList = new ArrayList<>();
        for (Map<String, Object> map : query.queryResults()) {
            NodeModel queryNode = (NodeModel) map.get("p");
            //System.out.println(queryNode);
            Neo4jBasicNode startNodeVo = new Neo4jBasicNode();
            startNodeVo.setIdentity(queryNode.getId());
            startNodeVo.setLabels(Arrays.asList(queryNode.getLabels()));
            List<Property<String, Object>> propertyList = queryNode.getPropertyList();
            HashMap<String, Object> proMap = new HashMap<>();
            for (Property<String, Object> stringObjectProperty : propertyList) {
                if (proMap.containsKey(stringObjectProperty.getKey())) {
                    throw new RuntimeException("数据重复");
                }
                proMap.put(stringObjectProperty.getKey(), stringObjectProperty.getValue());
            }
            startNodeVo.setProperties(proMap);
            nodeList.add(startNodeVo);
        }
        session.clear();
        return nodeList;
    }

    /*查询精神节点间关系*/
    @GetMapping("/spirit-relation")
    public List<Neo4jQueryRelation> querySpiritRelation(String algorism) {
        //String cypherSql = "match l=(n)-[]-(m) WHERE labels(n)=['spirit'] or labels(n)=['vipspirit'] return l";
        String cypherSql = "match l=(n)-[]-(m) WHERE (labels(n)=['spirit'] or labels(n)=['vipspirit']) " +
                "AND (labels(m)=['spirit']or labels(m)=['vipspirit']) return n.neihan as n1,l,m.neihan as n2";
        Result query = session.query(cypherSql, new HashMap<>());
        ArrayList<Neo4jQueryRelation> returnList = new ArrayList<>();
        for (Map<String, Object> map : query.queryResults()) {
            InternalPath ps = (InternalPath) map.get("l");
            String neihan1 = (String) map.get("n1");
            String neihan2 = (String) map.get("n2");
//            System.out.println("---------------------------------------");
//            System.out.println(neihan1);
//            System.out.println(neihan2);
            /*组装 relation*/
            Neo4jQueryRelation neo4JQueryRelation = new Neo4jQueryRelation();
            Relationship relationship = ps.relationships().iterator().next();
            neo4JQueryRelation.setStart(relationship.startNodeId());
            neo4JQueryRelation.setEnd(relationship.endNodeId());
            neo4JQueryRelation.setIdentity(relationship.id());
            neo4JQueryRelation.setType(relationship.type());
            Map<String, Object> newpro = new HashMap<>();
            newpro.put("property", relationship.asMap().get("property"));
            if (Objects.equals(algorism, "cosine")) newpro.put("similarity", cosSimilarityByString(neihan1, neihan2));
            else newpro.put("similarity", "无");
            //System.out.println(newpro);
            neo4JQueryRelation.setProperties(newpro);

            returnList.add(neo4JQueryRelation);
        }
        session.clear();
        return returnList;
    }

    /*查询某个节点*/
    @GetMapping("/searchNode")
    public List<Neo4jBasicNode> searchNode(String string, String[] label) {
        StringBuilder cypherSql = new StringBuilder("MATCH (n) where n.name=~'.*");
        cypherSql.append(string);
        for (int i = 0; i < label.length; i++) {
            if (i == 0) {
                cypherSql.append(".*' and (labels(n)=['").append(label[i]).append("']");
            } else {
                cypherSql.append(" or labels(n)=['").append(label[i]).append("']");
            }
            if (label[i].equals("spirit")) {
                cypherSql.append(" or labels(n)=['period'] or labels(n)=['vipspirit']");
            }
        }
        cypherSql.append(") RETURN n");
        Result query = session.query(cypherSql.toString(), new HashMap<>());
        ArrayList<Neo4jBasicNode> nodeList = new ArrayList<>();
        for (Map<String, Object> map : query.queryResults()) {
            NodeModel queryNode = (NodeModel) map.get("n");
            //System.out.println(queryNode);
            Neo4jBasicNode startNodeVo = new Neo4jBasicNode();
            startNodeVo.setIdentity(queryNode.getId());
            startNodeVo.setLabels(Arrays.asList(queryNode.getLabels()));
            List<Property<String, Object>> propertyList = queryNode.getPropertyList();
            HashMap<String, Object> proMap = new HashMap<>();
            for (Property<String, Object> stringObjectProperty : propertyList) {
                if (proMap.containsKey(stringObjectProperty.getKey())) {
                    throw new RuntimeException("数据重复");
                }
                proMap.put(stringObjectProperty.getKey(), stringObjectProperty.getValue());
            }
            startNodeVo.setProperties(proMap);
            nodeList.add(startNodeVo);
        }
        session.clear();
        return nodeList;
    }

//    @GetMapping("/congress")
//    public List<MapNode> getCongress() {
//        String cypherSql = "MATCH (p: congress) RETURN p";
//        Random rand = new Random();
//        Result query = session.query(cypherSql, new HashMap<>());
//        ArrayList<MapNode> nodeList = new ArrayList<>();
//        for (Map<String, Object> map : query.queryResults()) {
//            NodeModel queryNode = (NodeModel) map.get("p");
//            MapNode startNodeVo = new MapNode();
//            startNodeVo.setIdentity(queryNode.getId());
//            startNodeVo.setLabels(Arrays.asList(queryNode.getLabels()));
//            List<Property<String, Object>> propertyList = queryNode.getPropertyList();
//            HashMap<String, Object> proMap = new HashMap<>();
//            for (Property<String, Object> stringObjectProperty : propertyList) {
//                if (proMap.containsKey(stringObjectProperty.getKey())) {
//                    throw new RuntimeException("数据重复");
//                }
//                if (stringObjectProperty.getKey().equals("place")) {
//                    String addr = (String) stringObjectProperty.getValue();
//                    //place有两个地点如:中共一大
//                    double lng;
//                    double lat;
//                    if (addr.split("、").length > 1) {
//                        Map<String, BigDecimal> latAndLng1 = getLatAndLngByAddress(addr.split("、")[0]);
//                        lng = doubleValue(latAndLng1.get("lng"));
//                        lat = doubleValue(latAndLng1.get("lat"));
//                        proMap.put("lng", latAndLng1.get("lng"));
//                        proMap.put("lat", latAndLng1.get("lat"));
//                        startNodeVo.setLng(lng);
//                        startNodeVo.setLat(lat);
//                        Map<String, BigDecimal> latAndLng2 = getLatAndLngByAddress(addr.split("、")[1]);
//                        lng = doubleValue(latAndLng2.get("lng"));
//                        lat = doubleValue(latAndLng2.get("lat"));
//                        proMap.put("lng2", lng);
//                        proMap.put("lat2", lat);
//                    } else if (addr.equals("莫斯科近郊") || addr.contains("莫斯科")) {
//                        proMap.put("lng", 37.36);
//                        proMap.put("lat", 55.45);
//                        startNodeVo.setLng(37.36);
//                        startNodeVo.setLat(55.45);
//                    } else {
//                        Map<String, BigDecimal> latAndLng = getLatAndLngByAddress(addr);
//                        double rand1 = (rand.nextInt(2)==0)?rand.nextDouble()-0.5:0.5-rand.nextDouble();
//                        double rand2 = (rand.nextInt(2)==0)?rand.nextDouble()-0.5:0.5-rand.nextDouble();
//                        lng = doubleValue(latAndLng.get("lng"))+rand1;
//                        lat = doubleValue(latAndLng.get("lat"))+rand2;
//                        //lng = doubleValue(latAndLng.get("lng"))+rand.nextInt(20);
//                        //lat = doubleValue(latAndLng.get("lat"))+rand.nextInt(20);
//                        proMap.put("lng", lng);
//                        proMap.put("lat", lat);
//                        startNodeVo.setLng(lng);
//                        startNodeVo.setLat(lat);
//                    }
//                }
//                proMap.put(stringObjectProperty.getKey(), stringObjectProperty.getValue());
//            }
//            startNodeVo.setProperties(proMap);
//            nodeList.add(startNodeVo);
//        }
//        session.clear();
//        return nodeList;
//    }

    @GetMapping("/congress")
    public List<ClusterNode> getCongress(int[] range) {
        String cypherSql = "MATCH (p: congress) where p.year>='" + range[0] + "' and p.year<='" + range[1] + "' RETURN p";
        Random rand = new Random();
        Result query = session.query(cypherSql, new HashMap<>());
        ArrayList<Neo4jBasicNode> nodeList = new ArrayList<>();
        for (Map<String, Object> map : query.queryResults()) {
            NodeModel queryNode = (NodeModel) map.get("p");
            Neo4jBasicNode startNodeVo = new Neo4jBasicNode();
            startNodeVo.setIdentity(queryNode.getId());
            startNodeVo.setLabels(Arrays.asList(queryNode.getLabels()));
            List<Property<String, Object>> propertyList = queryNode.getPropertyList();
            HashMap<String, Object> proMap = new HashMap<>();
            for (Property<String, Object> stringObjectProperty : propertyList) {
                if (proMap.containsKey(stringObjectProperty.getKey())) {
                    throw new RuntimeException("数据重复");
                }
                proMap.put(stringObjectProperty.getKey(), stringObjectProperty.getValue());
            }
            startNodeVo.setProperties(proMap);
            nodeList.add(startNodeVo);
        }

        List<ClusterNode> temp = new ArrayList<>();
        Set<String> placeSet = new HashSet<>();
        /*获得全部的地点*/
        for (Neo4jBasicNode Neo4jBasicNode : nodeList) {
            String place = (String) Neo4jBasicNode.getProperties().get("place");
            if (place.split("、").length > 1) {
                placeSet.add(place.split("、")[0]);
                placeSet.add(place.split("、")[1]);
            } else {
                placeSet.add(place);
            }
        }
        /*根据每个地点创建ClusterNode*/
        for (String s : placeSet) {
            ClusterNode clusterNode = new ClusterNode();
            /*有两个地点的，封装到不同的簇中*/
            if (s.equals("莫斯科近郊") || s.contains("莫斯科")) {
                clusterNode.setLng(doubleValue(37.36));
                clusterNode.setLat(doubleValue(55.45));
                clusterNode.setPlace(s);
                clusterNode.setClusterData(new ArrayList<>());
                temp.add(clusterNode);
            } else {
                Map<String, BigDecimal> latAndLng = getLatAndLngByAddress(s);
                clusterNode.setLng(doubleValue(latAndLng.get("lng")));
                clusterNode.setLat(doubleValue(latAndLng.get("lat")));
                clusterNode.setPlace(s);
                clusterNode.setClusterData(new ArrayList<>());
                temp.add(clusterNode);
            }
        }
        /*组装ClusterNode*/
        for (Neo4jBasicNode Neo4jBasicNode : nodeList) {
            String place = (String) Neo4jBasicNode.getProperties().get("place");
            for (ClusterNode clusterNode : temp) {
                if (clusterNode.getPlace().equals(place) || place.contains(clusterNode.getPlace())) {
                    clusterNode.getClusterData().add(Neo4jBasicNode);
                }
            }
        }
        for (ClusterNode clusterNode : temp) {
            clusterNode.setPoint_count(clusterNode.getClusterData().size());
            clusterNode.setCluster(clusterNode.getPoint_count() > 1);
            clusterNode.setCluster_id(clusterNode.getClusterData().get(0).getIdentity());
        }

        session.clear();
        return temp;
    }


    //如果数据库存在则直接从数据库中获取，否则根据baidu api接口根据地名获取lat&lng保存到数据库
    public Map<String, BigDecimal> getLatAndLngByAddress(String addr) {
        QueryWrapper<Place> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(Place::getPlaceName, addr);
        Place searchPlace = placeMapper.selectOne(queryWrapper);
        if (searchPlace == null) {
            System.out.println("调用baidu API");
            String address = "";
            String lat = "";
            String lng = "";
            try {
                address = java.net.URLEncoder.encode(addr, "UTF-8");
            } catch (UnsupportedEncodingException e1) {
                e1.printStackTrace();
            }
            //ak1=1lEtWYuHwK2YMOH1QL0u0NmAcxe3YaFC
            //ak2=czNQ1PvUkNR67DyRy8l1kLtKTIYDGIQI
            String url = String.format("https://api.map.baidu.com/geocoding/v3/?"
                    + "ak=1lEtWYuHwK2YMOH1QL0u0NmAcxe3YaFC&output=json&address=%s", address);
            URL myURL = null;
            URLConnection httpsConn = null;
            //进行转码
            try {
                myURL = new URL(url);
            } catch (MalformedURLException e) {
                System.out.println(e);
            }
            try {
                httpsConn = (URLConnection) myURL.openConnection();
                if (httpsConn != null) {
                    InputStreamReader insr = new InputStreamReader(
                            httpsConn.getInputStream(), "UTF-8");
                    BufferedReader br = new BufferedReader(insr);
                    String data = null;
                    if ((data = br.readLine()) != null) {
                        lat = data.substring(data.indexOf("\"lat\":")
                                + ("\"lat\":").length(), data.indexOf("},\"precise\""));
                        lng = data.substring(data.indexOf("\"lng\":")
                                + ("\"lng\":").length(), data.indexOf(",\"lat\""));
                    }
                    insr.close();
                }
            } catch (IOException e) {
                System.out.println(e);
            }
            Map<String, BigDecimal> map = new HashMap<>();
            map.put("lat", new BigDecimal(lat));
            map.put("lng", new BigDecimal(lng));
            Place place = new Place();
            place.setPlaceName(addr);
            place.setLat(new BigDecimal(lat));
            place.setLng(new BigDecimal(lng));
            placeMapper.insert(place);
            return map;
        } else {
            System.out.println("不调用baidu API");
            Map<String, BigDecimal> map = new HashMap<>();
            map.put("lat", searchPlace.getLat());
            map.put("lng", searchPlace.getLng());
            return map;
        }
    }


    /*查询某个节点相邻的边*/
    @GetMapping("/subrelation")
    public List<Neo4jQueryRelation> querySearch(String content) {
        String cypherSql = "MATCH r=(n{name:'" + content + "'})-[]-() RETURN r";
        Result query = session.query(cypherSql, new HashMap<>());
        ArrayList<Neo4jQueryRelation> returnList = new ArrayList<>();
        for (Map<String, Object> map : query.queryResults()) {
            InternalPath ps = (InternalPath) map.get("r");
            /*组装 relation*/
            Neo4jQueryRelation neo4JQueryRelation = new Neo4jQueryRelation();
            Relationship relationship = ps.relationships().iterator().next();
            neo4JQueryRelation.setStart(relationship.startNodeId());
            neo4JQueryRelation.setEnd(relationship.endNodeId());
            neo4JQueryRelation.setIdentity(relationship.id());
            neo4JQueryRelation.setType(relationship.type());
            neo4JQueryRelation.setProperties(relationship.asMap());
            returnList.add(neo4JQueryRelation);
        }
        session.clear();
        return returnList;
    }

    /*查询某个节点相邻的点*/
    @GetMapping("/subnode")
    public Set<Neo4jBasicNode> searchCongressNode(String content, @RequestParam(required = false) String[] label) {
        String cypherSql = "MATCH (n:conference{name:'" + content + "'}) return n";
        if (label.length != 0) {
            cypherSql += " UNION MATCH (p{name:'" + content + "'})-[]-(n) where (";
            for (int i = 0; i < label.length; i++) {
                if (i == 0) {
                    cypherSql += "labels(n)=['" + label[i] + "']";
                } else {
                    cypherSql += " or labels(n)=['" + label[i] + "']";
                }
                if (label[i].equals("spirit")) {
                    cypherSql += " or labels(n)=['period'] or labels(n)=['vipspirit']";
                }
            }
            cypherSql += ") return n";
        }
        Result query = session.query(cypherSql, new HashMap<>());
        Set<Neo4jBasicNode> returnList = new HashSet<>();
        for (Map<String, Object> map : query.queryResults()) {
            NodeModel queryStartNode = (NodeModel) map.get("n");
            /*组装 startNode*/
            Neo4jBasicNode startNodeVo = new Neo4jBasicNode();
            Neo4jBasicNode startNodeVo2 = new Neo4jBasicNode();
            startNodeVo.setIdentity(queryStartNode.getId());
            startNodeVo2.setIdentity(queryStartNode.getId());
            startNodeVo.setLabels(Arrays.asList(queryStartNode.getLabels()));
            startNodeVo2.setLabels(Arrays.asList(queryStartNode.getLabels()));

            List<Property<String, Object>> propertyList = queryStartNode.getPropertyList();
            HashMap<String, Object> proMap = new HashMap<>();
            for (Property<String, Object> stringObjectProperty : propertyList) {
                if (proMap.containsKey(stringObjectProperty.getKey())) {
                    throw new RuntimeException("数据重复");
                }
                proMap.put(stringObjectProperty.getKey(), stringObjectProperty.getValue());
            }
            String place = (String) proMap.get("place"); //place有两个地点如:中共一大。分成两个node存
            if (place != null && place.split("、").length > 1) {
                String place1 = place.split("、")[0];
                String place2 = place.split("、")[1];

                proMap.put("place", place1);
                startNodeVo.setProperties(proMap);
                if (!checkRepeatPlace(returnList, startNodeVo)) {
                    returnList.add(startNodeVo);
                }
//                System.out.println("节点一:" + startNodeVo.getIdentity() + "地点为：" + startNodeVo.getProperties().get("place") + "proMap:" + proMap.get("place"));

                proMap.put("place", place2);
                startNodeVo2.setProperties(proMap);
                if (!checkRepeatPlace(returnList, startNodeVo2)) {
                    returnList.add(startNodeVo2);
                }
//                System.out.println("节点二:" + startNodeVo2.getIdentity() + "地点为：" + startNodeVo2.getProperties().get("place") + "proMap:" + proMap.get("place"));
            } else {
                startNodeVo.setProperties(proMap);
                returnList.add(startNodeVo);
            }
//            if(label.length!=0) {
//                /*组装 endNode*/
//                Neo4jBasicNode endNodeVo = new Neo4jBasicNode();
//                endNodeVo.setIdentity(queryEndNode.getId());
//                endNodeVo.setLabels(Arrays.asList(queryEndNode.getLabels()));
//
//                List<Property<String, Object>> propertyList2 = queryEndNode.getPropertyList();
//                HashMap<String, Object> proMap2 = new HashMap<>();
//                for (Property<String, Object> stringObjectProperty : propertyList2) {
//                    if (proMap2.containsKey(stringObjectProperty.getKey())) {
//                        throw new RuntimeException("数据重复");
//                    }
//                    proMap2.put(stringObjectProperty.getKey(), stringObjectProperty.getValue());
//                }
//                String place2 = (String) proMap2.get("place"); //place有两个地点如:中共一大。分成两个node存
//                if (place2 != null && place2.split("、").length > 1) {
//                    proMap2.put("place", place2.split("、")[0]);
//                    endNodeVo.setProperties(proMap2);
//                    if (!checkRepeatPlace(returnList, endNodeVo)) {
//                        returnList.add(endNodeVo);
//                    }
//
//                    proMap2.put("place", place2.split("、")[1]);
//                    endNodeVo.setProperties(proMap2);
//                    if (!checkRepeatPlace(returnList, endNodeVo)) {
//                        returnList.add(endNodeVo);
//                    }
//                } else {
//                    endNodeVo.setProperties(proMap2);
//                    returnList.add(endNodeVo);
//                }
//            }
        }
        session.clear();
        return returnList;
    }

    public boolean checkRepeatPlace(Set<Neo4jBasicNode> returnList, Neo4jBasicNode node) {
        for (Neo4jBasicNode neo4jBasicNode : returnList) {
            if (node.getIdentity().equals(neo4jBasicNode.getIdentity())) {
                return true;
            }
        }
        return false;
    }
}
